<script runat=server>
Function includeitems(ByVal strSQL As String,ByVal hrefname As String ,ByVal i As String ,ByVal authorid As String ,ByVal continue As String ) As String 
Dim  strItem As String =""
Dim totalRecords As Integer=0
Try
	Dim strConn As String
	strConn=ConfigurationSettings.appSettings("conn")
	Dim myConn As SqlConnection  = _
	New SqlConnection(strConn)
	myConn.Open				
	Dim myCom As SqlCommand = _
	New SqlCommand(strSQL,myConn)
	Dim myReader As SqlDataReader = _
	myCom.ExecuteReader()
	strItem ="<ul>"
    	While myReader.Read()
		totalRecords +=1
		strItem  += "<li><a href=" & hrefname 
		strItem  += "?itemid="
		strItem  += myReader("No").toString()
		strItem  +=  continue & ">"
		strItem  += myReader("Name") & "</a>"		
		if i =1 or i=2 then
		  strItem  += " Written by "
		  strItem  += myReader("AuthorName")
		end if
		if myReader("ItemStyle") <>"" then			 
		  strItem  +=  " " & myReader("ItemStyle")
		end if
		if i=2 then			 
		  strItem  +=  ", Price:" 
		  strItem  += myReader("SalesPrice").toString()
		end if
		strItem  += "."	
		strItem  += "</li>"		
	End While
	myReader.Close
	myConn.Close
	strItem  += "</ul>"
	if totalRecords>10 then
		strItem  += " <a href=authors.aspx?authorid=" 
		strItem  += authorid & "> and more ...</a><br>"
	end if
Catch objError As Exception
	strItem = "<b>* Error</b>: " & _
	objError.Message & "<p />"
End Try
includeitems=strItem
End Function

Function browseitems(ByVal strSQL As String) As String
Dim  strItem As String =""
Try
	Dim strConn As String
	strConn=ConfigurationSettings.appSettings("conn")
	Dim myConn As SqlConnection  = _
	New SqlConnection(strConn)
	myConn.Open				
	Dim myCom As SqlCommand = _
	New SqlCommand(strSQL,myConn)
	Dim myReader As SqlDataReader = _
	myCom.ExecuteReader()
	strItem ="<ul>"
    	While myReader.Read()
	      	strItem  += "<li><a href=browsesubject.aspx?type=classese" 
		strItem  += "&id=" 
		strItem  += myReader("SubjectID") & ">"
		strItem  += myReader("SubjectName") & "</a> > "
		strItem  += "<a href=browsesubject.aspx?type=groups" 
		strItem  += "&id=" 
		strItem  += myReader("ClassID") & "&aid=" & myReader("SubjectID")
		strItem  += "&scid=" & myReader("SubCateID")
		strItem  += "&sid=" & session.SessionID & ">"
		strItem  += myReader("ClassName") & "</a> > "
		strItem  += "<a href=browsesubject.aspx?type=category" 
		strItem  += "&id="   
		strItem  += myReader("GroupID") & "&aid=" & myReader("SubjectID")
		strItem  += "&scid=" & myReader("SubCateID")
		strItem  += "&sid=" & session.SessionID & ">"
		strItem  += myReader("GroupName") & "</a> > "
		strItem  += "<a href=browsesubject.aspx?type=subcategory" 
		strItem  += "&id=" 		 
		strItem  += myReader("CateID") & "&aid=" & myReader("SubjectID")
		strItem  += "&scid=" & myReader("SubCateID")
		strItem  += "&sid=" & session.SessionID & ">"
		strItem  += myReader("CateName") & "</a> > "
		strItem  += "<a href=alphabet.aspx?type=subcategory" 
		strItem  += "&id=" 
	      	strItem  += myReader("SubCateID")  & "&aid=" & myReader("SubjectID")
		strItem  += "&scid=" & myReader("SubCateID")
		strItem  += "&sid=" & session.SessionID & ">"
	      	strItem  += myReader("SubCateName") & "</a> " 
		strItem  += "</li>"
	End While
	myReader.Close
	myConn.Close
	strItem  += "</ul>"				
 Catch objError As Exception
	strItem = "<b>* Error</b>: " & _
	objError.Message & "<p />"
 End Try
 browseitems=strItem
End Function

Function greatebuyitems(ByVal strSQL As String, ByVal currentImage As String, ByVal hrefname As String, ByVal currentItemID As String, ByVal greatebuy As String,ByVal continue As String) As String
Dim  strItems As String =""
strItems="<table width=100% border=0 >"
strItems += "<tr><td colspan=2 "
strItems += " valign=middle>"
strItems += "Buy this book with "
Dim strImages As String =""
strImages  += "<img src=books/" 
strImages  +=  currentImage 
strImages  +=  " height=50 align=middle border=0>"

Dim strListPrice=0
Dim strSalesPrice=0 

Try
	Dim strConn As String
	strConn=ConfigurationSettings.appSettings("conn")
	Dim myConn As SqlConnection  = _
	New SqlConnection(strConn)
	myConn.Open				
	Dim myCom As SqlCommand = _
	New SqlCommand(strSQL,myConn)
	Dim myReader As SqlDataReader = _
	myCom.ExecuteReader()
	Dim  No=""
	Dim  Name=""
	Dim  SalesPrice=0
	Dim  ListPrice=0
	Dim  SalesDiscount =0
	Dim  ImagePathSmall=""
	Dim strItemID =""
    	While myReader.Read()   
		  No=myReader("No").toString()
		  Name=myReader("Name")
		  SalesPrice=myReader("SalesPrice").toString()
		  ListPrice=myReader("ListPrice").toString()
		  SalesDiscount=myReader("SalesDiscount").toString()
		  ImagePathSmall=myReader("ImagePathSmall") 
		  if No <> currentItemID then
			  strItems  += "<a href=" & hrefname 
			  strItems  += "?itemid="		  		  
			  strItems  += No & continue & ">"
			  strItems  += Name
			  strItems  += "</a> by "
			  strItems  += myReader("AuthorName")
			  if myReader("ItemStyle") <>"" then			 
				  strItems  +=  " " & myReader("ItemStyle")
			  end if		  
			  strImages  += " + <a href=" 
			  strImages  += hrefname & "?itemid=" & No
			  strImages  += continue
			  strImages  += "><img src=books/" 
			  strImages  += ImagePathSmall
			  strImages  += " height=50 align=middle border=0></a>"
			  strItems  +=  " " 
		 end if  
		  strListPrice= strListPrice + ListPrice
		  strSalesPrice=strSalesPrice +  SalesPrice 
		  strItemID  += "<input type=hidden name=itemids value='" & No
		  strItemID  += "'>"
		  strItemID  += "<input type=hidden name='itemname" 
		 strItemID  += No & "' value='" & Name
		  strItemID  += "'><input type=hidden name='Image" 
		strItemID  += No & "' value='" & ImagePathSmall & "'>"
		  strItemID  += "<input type=hidden name='itemprice" 
		strItemID  += No & "' value='" & SalesPrice
		   strItemID  += "'><input type=hidden name='itemlistprice" 
		strItemID  += No & "' value='" & ListPrice
		strItemID  += "'><input type=hidden name='itemdiscount" 
		strItemID  += No & "' value='" & SalesDiscount
		   strItemID  += "'><input type=hidden name='itemauthorname" 
		strItemID  += No & "' value='" & myReader("AuthorName")
		strItemID  += "'><input type=hidden name='itemweight" 
		strItemID  += No & "' value='" & myReader("Weight")
		   strItemID  += "'><input type=hidden name='itemproname" 
		strItemID  += No & "' value='" & myReader("ProName")
		   strItemID  += "'><input type=hidden name='itemstyle" 
		strItemID  += No & "' value='" & myReader("ItemStyle")
		   strItemID  += "'><input type=hidden name='itemavailable" 
		strItemID  += No & "' value='" & myReader("Available")
		  strItemID  += "'><input type=hidden name='itemqtty" 
		strItemID  += No & "' value='1'>"		 
	End While
	myReader.Close
	myConn.Close
	strItems +=  "<br><br></td></tr><tr><td>" 
	strItems  + = strImages + "</td><td>"
	strItems +=  "Total List Price: " & formatnumber(strListPrice,0)
	strItems += "<br>Buy Together Today: " 
	strItems  += formatnumber(strSalesPrice,0)
	strItems  += "<form method=post action=addtocart.aspx" 
	strItems  += "?sid=" & session.SessionID & "&itemid=" 
	strItems  += currentItemID 
	strItems  += continue & ">"
	strItems  += "<input type=image src='images/add-to-cart.gif'>"	
	strItems  += "<input type=hidden name=fromcart value='0'>"
	strItems  += "<input type=hidden name='Relations' value='" 
	strItems  += greatebuy & "'>"
	strItems  += strItemID 
    	strItems  += "</form></td></tr></table>"
 Catch objError As Exception
	strItems = "<b>* Error</b>: " & _
	objError.Message & "<p />"
 End Try
 greatebuyitems=strItems 
End Function

Function carts()  As String
  Dim strItems As String =""  
  if session("shoppingcart")>0 then    	
	Dim Amount=0, No As Integer=1	
	Dim ItemName=""
	Dim AuthorName=""
	Dim Quantity=0
	Dim SalesPrice=0
	Dim ItemStyle=""	
	for No = 1 to session("shoppingcart")				 	 					   					  
		ItemName=Seperate(session("shoppingcarts"),"itemname" & No) 
		AuthorName=Seperate(session("shoppingcarts"),"itemauthorname" & No) 
		Quantity=Seperate(session("shoppingcarts"),"itemqtty" & No)
		SalesPrice=Seperate(session("shoppingcarts"),"itemprice" & No)  	
		ItemStyle=Seperate(session("shoppingcarts"),"itemstyle" & No)
		Amount=Amount+ Quantity* SalesPrice		  		  
		strItems  += "<b>" & ItemName & "</b>"
		strItems  += "</a><br>by "
		strItems  += AuthorName
		if ItemStyle <>"" then			 
		  strItems  +=  " " + ItemStyle
		end if
		strItems  +=  "<br>Quantity: " + Quantity
		strItems  +=  "<br>Price: " + formatnumber(SalesPrice,0)
		strItems  += "<hr><br>"		  		  
	next	
	strItems  += "Total: VND <b><font color=red>" 
	strItems  += FormatNumber(Amount ,0) 
	strItems  += "<b></font><br>"	
	strItems  += "<hr><br><a href=viewcart.aspx?"
	
	strItems  += "><img src='images/viewcart.gif' border=0></a>"
  else
	  strItems = ""
  end if
  carts=strItems 
End Function
Function reviews(ByVal strSQL as String) As String
Dim  strItem As String =""
Try
	Dim strConn As String
	strConn=ConfigurationSettings.appSettings("conn")
	Dim myConn As SqlConnection  = _
	New SqlConnection(strConn)
	myConn.Open				
	Dim myCom As SqlCommand = _
	New SqlCommand(strSQL,myConn)
	Dim myReader As SqlDataReader = _
	myCom.ExecuteReader()
    	While myReader.Read()	
	  strItem  += "<img src='icons/stars" 
	  strItem  += myReader("ResultID") 
	  strItem  += ".gif' border=0>"
	  strItem  +=  "<b>" & myReader("Subject") 
	   strItem  += "</b>, "		
	  strItem  += myReader("ReviewDate") 
	   strItem  += "<br>"
	  strItem  += "Reviewer: <b>" 
	  strItem  += myReader("FullName")
	  strItem  += "</b>(Những cuốn sách "
	  strItem  += "tôi dã dánh giá)<br>" 
	  strItem  += replace(myReader("Contents"),"-","<br>-") 
	  strItem  += "<b>"		 
	  strItem  += "<br><br>"
	  strItem  += "</li>"		
	End While
	myReader.Close
	myConn.Close
	strItem  += "<br>"
Catch objError As Exception
	strItem = "<b>* Error</b>: " & _
	objError.Message & "<p />"
End Try
reviews=strItem
End Function
</script>